package agenda

import scala.collection.mutable.ArrayBuffer

class Agenda(private val _ownerName: String) {
  require(_ownerName != null)

  def ownerName = _ownerName

  private val entries = new ArrayBuffer[Entry]();

  def hasEntry(entry: Entry): Boolean = {
    entries.contains(entry);
  }

  def addEntry(entry: Entry): Unit = {
    require(entry != null)
    require(entry.agenda == this)
    require(!this.hasEntry(entry))
    entries += entry
  }

  def removeEntry(entry: Entry): Unit = {
    require(entry != null)
    require(entry.agenda == this)
    require(this.hasEntry(entry))
    entries -= entry
  }
  
  def removeEntries (condition: () => Boolean, getIndex : () => Int, after : () => Unit) {
	  while(condition()){
	 	  entries.remove(getIndex())
	 	  after()
	  }
  }
}